package com.zlp.mall.portal.modules.pms.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zlp.mall.common.api.RespCode;
import com.zlp.mall.common.exception.CustomException;
import com.zlp.mall.common.util.MethodUtil;
import com.zlp.mall.portal.modules.pms.model.SkuStock;
import com.zlp.mall.portal.modules.pms.mapper.SkuStockMapper;
import com.zlp.mall.portal.modules.pms.service.SkuStockService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
 * <p>
 * sku的库存 服务实现类
 * </p>
 *
 * @author ZouLiPing
 * @since 2021-10-13
 */
@Service
@Slf4j(topic = "SkuStockServiceImpl")
public class SkuStockServiceImpl extends ServiceImpl<SkuStockMapper, SkuStock> implements SkuStockService {

    @Override
    public List<SkuStock> getByProductId(Long productId) {

        log.info("getByProductId.req productId={}",productId);
        LambdaQueryWrapper<SkuStock> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(SkuStock::getProductId,productId);
        return this.list(queryWrapper);
    }

    @Override
    public SkuStock getBySkuId(Long productSkuId) {
        log.info("getBySkuId.req productSkuId={}",productSkuId);
        SkuStock skuStock = this.getById(productSkuId);
        if (Objects.isNull(skuStock)) throw new CustomException(RespCode.FRONT_PMS_3001, MethodUtil.getLineInfo());
        return skuStock;
    }
}
